home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / tblt / tblt⁄menu.c < prev    next >
Encoding:
Text File  |  1986-09-06  |  4.1 KB  |  161 lines  |  [TEXT/MACA]

  1. /*
  2.  * menu.c - menu handling for Tablut.
  3.  *
  4.  */
  5.  
  6. #include <quickdraw.h>
  7. #include <window.h>
  8. #include <menu.h>
  9. #include <desk.h>
  10. #include <resource.h>
  11.  
  12. #define APPLEMENU 1    /* Menu ID for Apple menu    */
  13. #define FILEMENU 2    /* Menu ID for File menu    */
  14. #define EDITMENU 3    /* Menu ID for Edit menu    */
  15. #define RULEMENU 4    /* Menu ID for Rules menu    */
  16. #define LASTMENU 4    /* Number of menus        */
  17.  
  18.     /* items in the Apple menu    */
  19. #define DLGABOUT    256    /* About Tablut...    */
  20.  
  21.     /* Items in the File menu    */
  22. #define NEWGAME        1    /* play another round    */
  23. #define OPENGAME    2    /* open a saved game    */
  24. #define SAVEGAME    3    /* save this game    */
  25. #define SAVEASGAME    4    /* save under a new name */
  26. /*----5---*/
  27. #define QUITTO        6    /* quit to another program */
  28. #define IQUIT        7    /* quit the program    */
  29.  
  30.     /* items in the Rules menu    */
  31. #define SAYPIECES    1    /* show the Piece rules    */
  32. #define DLGPIECES    300    /* ...their dialog ID    */
  33. #define SAYMOVES    2    /* show the Movement rules */
  34. #define DLGMOVES    301    /* ...their dialog ID    */
  35. #define SAYCAPTURE    3    /* show the Capture rules */
  36. #define DLGCAPTURE    302    /* ...their dialog ID    */
  37. #define SAYOBJECT    4    /* show the Objective rules */
  38. #define DLGOBJECT    303    /* ...their dialog ID    */
  39. #define SAYREFERS    5    /* show the game references */
  40. #define DLGREFERS    304    /* ...their dialog ID    */
  41.  
  42. MenuHandle mymenus[LASTMENU + 1]; /* menus[1..LASTMENU]    */
  43.  
  44. /*
  45.  * docommand() - handle a command given through a menu selection.
  46.  *
  47.  * If the command is Quit, we return true, else false.
  48.  * Since the menu was highlighted by MenuSelect, we must finish
  49.  * by unhighlighting it to indicate we're done.
  50.  */
  51. int
  52. docommand(mresult)
  53. long    mresult;    /* the command to execute (a menu item)    */
  54. {
  55.     int refnum;
  56.     int themenu;
  57.     int theitem;
  58.     char name[255];
  59.     GrafPtr saveport;        /* for saving current port    */
  60.     int     returns;
  61.  
  62.     returns = 0;        /* assume Quit not selected    */
  63.     themenu = HiWord(mresult);    /* get the menu selected    */
  64.     theitem = LoWord(mresult);    /* ...and the item of that menu    */
  65.     switch (themenu) {
  66.     case 0:         /* no selection -- do nothing    */
  67.         break;
  68.  
  69.     case APPLEMENU:
  70.         if (theitem == 1) {    /* Tell about the program */
  71.         saydialog(DLGABOUT);
  72.         } else {        /* run a desk accessory    */
  73.         GetPort(&saveport);    /* preserve the port    */
  74.         GetItem(mymenus[APPLEMENU], theitem, name); /* get name */
  75.         refnum = OpenDeskAcc(name);/* run the desk accessory */
  76.         SetPort(saveport);
  77.         }
  78.         break;
  79.  
  80.     case FILEMENU: 
  81.         switch (theitem) {
  82.         case NEWGAME:    /* another round */
  83.             if (maysave()) {
  84.             newgame();
  85.             }
  86.             break;
  87.         case OPENGAME:    /* read an old game    */
  88.             if (maysave()) {
  89.             (void) opengame();
  90.             }
  91.             break;
  92.         case SAVEGAME:
  93.         case SAVEASGAME: /* save the current game */
  94.             (void) savegame(theitem == SAVEASGAME);
  95.             break;
  96.         case QUITTO:    /* launch another program */
  97.             if (maysave()) {
  98.             quittoprog();
  99.             }
  100.             break;
  101.         case IQUIT:    /* quit */
  102.             if (maysave()) {
  103.             returns = 1;
  104.             }
  105.             break;
  106.         }
  107.         break;
  108.  
  109.     case RULEMENU: 
  110.         switch (theitem) {
  111.         case SAYPIECES: saydialog(DLGPIECES); break;
  112.         case SAYMOVES: saydialog(DLGMOVES); break;
  113.         case SAYCAPTURE: saydialog(DLGCAPTURE); break;
  114.         case SAYOBJECT: saydialog(DLGOBJECT); break;
  115.         case SAYREFERS: saydialog(DLGREFERS); break;
  116.         }
  117.         break;
  118.     }
  119.     HiliteMenu(0);    /* we're done -- turn off the highlighting */
  120.     return(returns);
  121. }
  122.  
  123. /*
  124.  * setupmenus() - Initialize the menus and desk accessories (drivers).
  125.  */
  126.  
  127. setupmenus()
  128. {
  129.     int i;
  130.  
  131.     for (i = 1; i <= LASTMENU; i++) {
  132.     mymenus[i] = GetMenu(i);    /* our menu ID's start at 1    */
  133.     }
  134.  
  135.     AddResMenu(mymenus[APPLEMENU], 'DRVR');
  136.     for (i = 1; i <= LASTMENU; i++) {
  137.     /* insert menus; 0 => put at end */
  138.     InsertMenu(mymenus[i], 0);
  139.     }
  140.     DrawMenuBar();
  141. }
  142.  
  143. /*
  144.  * actmenus(), deactmenus() - activate/deactivate our window's menus.
  145.  */
  146. actmenus()
  147. {
  148.     DisableItem(mymenus[EDITMENU], 0);
  149.     EnableItem(mymenus[FILEMENU], 0);
  150.     EnableItem(mymenus[RULEMENU], 0);
  151.     DrawMenuBar();
  152. }
  153.  
  154. deactmenus()
  155. {
  156.     EnableItem(mymenus[EDITMENU], 0);
  157.     DisableItem(mymenus[FILEMENU], 0);
  158.     DisableItem(mymenus[RULEMENU], 0);
  159.     DrawMenuBar();
  160. }
  161.